const app = getApp(),url = app.globalData.url;
Page({

  data: {
    listArr:[
      
    ],
    alllist:[
      // {id:1,img:'/img/21.png',name:'2华为技术有限公司',},
      // {id:3,img:'/img/21.png',name:'2华为技术有限公司',},
      // {id:2,img:'/img/21.png',name:'2华为技术有限公司',},
    ],
    Nid:1,
    where:{
      pageNum:1,
      pageSize:1000,
    },
    allwhere:{
      // pageNum:1,
      // pageSize:20,
      companyName: "",
      currentPage: 1,
      industry: "",
      nature: "",
      pageSize: 36,
      size: "",
    },
    xuanid:1,//上拉加载使用到判断 是优选还是 全部
  },

  onLoad: function (options) {
    console.log(options)
    let that = this
    that.youxuan()

  },
  youxuan(){
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    // that.data.where.pageNum ++
    let where = that.data.where
    console.log(where)
    wx.request({
      url:url+'enterprise/getGoodEnterpriseByPageInfo',//getEnterpriseByPageInfo
      method: "GET",
      data:where,
      success:function(res){
        console.log("1",res);
        var ret = res.data
        if(ret.code == 200){
          wx.hideLoading()
          // listdata=listdata.concat(arr2)
          that.setData({listArr:ret.data})
        }else{
          wx.hideLoading()
          wx.showToast({
            title: ret.message,
            icon:'none'
          })
        }
      }
    })
  },
  // 全部
  all(){
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    let allwhere = that.data.allwhere
    wx.request({
      url:url+'enterpriselib/getEnterpriseLibList',
      method: "POST",
      data:allwhere,
      success:function(res){
        console.log("全部",res);
        var ret = res.data
        if(ret.code == 200){
          wx.hideLoading() 
          that.setData({alllist:ret.data.content})
          // listdata=listdata.concat(arr2)
          // that.setData({listdata})
        }else{
          wx.hideLoading()
          wx.showToast({
            title: ret.message,
            icon:'none'
          })
        }
      }
    })
  },

  //点击类别 全部  最新
  butType(e){
    let that = this
    let tid = e.currentTarget.dataset.id
    console.log(tid)
    that.setData({Nid:tid,})
    if(tid == 1){
      that.youxuan()
      that.setData({xuanid:tid})
    }else{
      that.all()
      that.setData({xuanid:tid})
    }
  },
  // 搜索
  searchBut:function(e){
    var that = this
    let status = e.detail.value
    console.log('执行search',status)
    wx.request({
      header: {
        'content-type': 'application/json' // 默认值
      },
      url:url+ 'enterpriselib/getEnterpriseLibList',
      method: "POST",
      data:{
        companyName: status,
        currentPage: 1,
        industry: "",
        nature: "",
        pageSize: 936,
        size: "",
      },
      success:function(res){
        console.log("企业公司名",res);
        var ret = res.data
        if(ret.code == 200){
          var listArr = ret.data.content
          that.setData({listArr:listArr,alllist:listArr})
        }else{
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
  },
  prisedetail(e){
    let pid = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/prisedetail/prisedetail?id='+pid,
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    var Nid = that.data.Nid
    console.log(Nid)
    if(Nid == 1){
      // that.yxpage()
    }else{
      that.allpage()
    }
  },
  yxpage(){
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    that.data.where.pageNum ++
    let where = that.data.where
    let listdata = that.data.listArr
    console.log(where)
    wx.request({
      url:url+'enterprise/getGoodEnterpriseByPageInfo',
      method: "GET",
      data:where,
      success:function(res){
        wx.hideLoading()
        var ret = res.data
        console.log("yxpage",res);
        if(ret.code == 200){
          if(ret.data.contetent != undefined){
            let listArr=listdata.concat(ret.data)
            that.setData({listArr})

          }else{
            that.data.where.pageNum = 1
          }
          wx.hideLoading()
        }
      }
    })
  },
  allpage(){
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    that.data.allwhere.currentPage ++
    let allwhere = that.data.allwhere
    // let alllist = that.data.alllist
    wx.request({
      url:url+'enterpriselib/getEnterpriseLibList',
      method: "GET",
      data:allwhere,
      success:function(res){
        console.log("allpage",res);
        var ret = res.data
        if(ret.code == 200){
          if(res.data.content != undefined){
            alllist=alllist.concat(res.data.content)
            that.setData({alllist})

          }else{
            that.setData({alllist})
          }
          wx.hideLoading()  
        }
      }
    })
  },
  // /**
  //  * 用户点击右上角分享
  //  */
  // onShareAppMessage: function () {

  // }
})